package com.small.nacos.core.code;

import com.small.nacos.sys.env.EnvUtil;
import org.springframework.boot.ConfigurableBootstrapContext;
import org.springframework.boot.SpringApplication;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * @Author zhoujin
 * @Date 2022/10/31 19:24
 */
public class SpringApplicationRunListener implements org.springframework.boot.SpringApplicationRunListener {

    private final SpringApplication application;

    private final String[] args;

    public SpringApplicationRunListener(SpringApplication application, String[] args) {
        this.application = application;
        this.args = args;
    }

    @Override
    public void environmentPrepared(ConfigurableBootstrapContext bootstrapContext,
                                    ConfigurableEnvironment environment) {
        injectEnvironment(environment);
    }

    private void injectEnvironment(ConfigurableEnvironment environment) {
        EnvUtil.setEnvironment(environment);
    }
}
